package com.syni.mdd.yhd.common.all.controller.api.business;

import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsUserBusinessAuth;
import com.syni.mdd.yhd.common.all.service.BmsUserBusinessAuthService;
import com.syni.mdd.yhd.common.all.service.BmsUserBusinessService;
import com.syni.mdd.sjb.common.component.utils.feign.dto.mddAll.apiBusiness.ClaimBusinessDto;
import com.syni.mdd.sjb.common.component.utils.feign.dto.mddAll.apiUserBusiness.AddBusinessMemberDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @className UserBusinessRestApi
 * @description TOO
 * @Author cfx
 * @DATE 2020/5/22 15:27
 * @VERSION 1.0
 **/
@RestController
@RequestMapping("/apiUserBusiness")
public class UserBusinessRestApi {

    @Autowired
    BmsUserBusinessService bmsUserBusinessService;

    @Autowired
    BmsUserBusinessAuthService bmsUserBusinessAuthService;

    @PostMapping("/addBusinessMember")
    public RpcResponseVo addBusinessMember(@RequestBody AddBusinessMemberDto addBusinessMemberDto){
        Integer userId = bmsUserBusinessAuthService.findBusinessManager(addBusinessMemberDto.getBusinessId());
        Map<String,Object> createMap = bmsUserBusinessService.addBusinessAssistant(userId,addBusinessMemberDto.getBusinessId(),addBusinessMemberDto.getAssistantName(),
                "",addBusinessMemberDto.getPhone(),addBusinessMemberDto.getIdentifityCode());
        if(ResultMapHelper.isSuccess(createMap)){
            return RpcResponseVo.success(null, ResultMsg.HAND_SUCCESS);
        }
        RpcResponseVo rpcResponseVo = RpcResponseVo.result(ResultCode.CODE_ERROR_100,createMap.get("msg").toString());
        return rpcResponseVo;
    }
}
